//
//  CertificationViewController.m
//  TenThousand
//
//  Created by 我的 on 16/6/22.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "CertificationViewController.h"

@interface CertificationViewController ()

@end

@implementation CertificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"实名认证";
    [self createLeft:[UIImage imageNamed:@"ZHSZicon_03"] leftClick:^{
        [self.navigationController popViewControllerAnimated:YES];
    } right:nil rightClick:nil];
}


//点击立即认证
- (IBAction)certification:(id)sender {
    
    
    if ([_nameTF.text isEqualToString:@""]) {
         [ToastView showInfoWithStatus:@"请输入真实姓名"];
    } else {
        [self FengFu];
    }
    
}

- (void)FengFu {
    NSDate *date = [NSDate date];
    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];//时间格式模板
    dateformatter.dateFormat = @"yyyyMMddHHmmss";
    NSString *dateStr = [dateformatter stringFromDate:date];
    NSString *requestId = [self.Idnumber.text stringByAppendingString:[NSString stringWithFormat:@"_%@",dateStr]];
    NSString *loginName = [[NSUserDefaults standardUserDefaults]objectForKey:@"LoginName"];
    NSString *loginId = [[NSUserDefaults standardUserDefaults]objectForKey:@"LoginId"];
    NSDictionary *dic = @{
                          @"requestType":@"PFT0000",
                          @"requestId":requestId,
                          @"merchantCode":FengFuMerchantCode,
                          @"userIdIdentity":loginId,
                          @"payType":@"1",
                          @"userName":self.nameTF.text,
                          @"idNumber":self.Idnumber.text,
                          @"mobileNo":loginName,
                          @"realNameToken":@"",
                          @"noticeUrl":[NSString stringWithFormat:@"%@API/notice/yanznotice.aspx", noticeUrl],
                          @"successReturnUrl":@"",
                          @"failReturnUrl":@"",
                          };
    NSString *sign = [[[[[[[[[[[dic[@"requestType"] stringByAppendingString:dic[@"requestId"]] stringByAppendingString:dic[@"merchantCode"]] stringByAppendingString:dic[@"userIdIdentity"]] stringByAppendingString:dic[@"payType"]]stringByAppendingString:dic[@"userName"]] stringByAppendingString:dic[@"idNumber"]] stringByAppendingString:dic[@"mobileNo"]] stringByAppendingString:dic[@"realNameToken"]] stringByAppendingString:dic[@"noticeUrl"]] stringByAppendingString:dic[@"successReturnUrl"]] stringByAppendingString:dic[@"failReturnUrl"]];
    NSString *signature = [HMACMD5 HMACMD5WithString:sign WithKey:FengFuKEY];
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:dic];
    [dict setObject:signature forKey:@"signature"];
    [SumaPaySDK startService:dict callback:^(id resultDic, NSError *error) {
        NSLog(@"%@------------------%@", resultDic, error);
        NSDictionary *dic = [NetWorkManager dictionaryWithJsonString:resultDic];
        if ([dic[@"result"] integerValue] == 0) {
            if ([dic[@"msg"][@"result"] integerValue] == 00000) {
                [self realnameauth:requestId];
            }
        }
        
    }];

}


-(void)realnameauth:(NSString *)requestId {
    
    /**
     *  RealName   真实姓名
     *  LoginName  用户编号 (丰付第三方标识)
     *  RequestId  丰付流水号
     */
    NSString *loginName = [[NSUserDefaults standardUserDefaults]objectForKey:@"LoginName"];
    NSDictionary *para = @{
                           @"RealName":_nameTF.text,
                           @"LoginName":loginName,
                           @"RequestId":requestId
                           };
    
    
    [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"User.Realnameauth" withParaments:para withSuccessBlock:^(NSDictionary *object) {
        NSLog(@"%@",object);
    } withFailureBlock:^(NSError *error) {
        NSLog(@"%@",error);
    } progress:nil];
    
}

@end
